/* OPTIONS OBS=500  NOREPLACE ; */

/** Select non-AR plants in the ready-mix concrete industry from 2002 and 2007 CMF */
/* Select tabulated, non-Administrative-Records plants with positive shipments
   and specialization ratio > 0.90, and merge them with the set of plants that have 
   product trailer data and ready-mix concrete is one of the product codes. 
*/

%include "ASMimplibs.sas";


data concrete02 ; 
 set cmf.cmf2002 (KEEP=ar survu_id  firmid tab tab_f tab_ei tae tae_f tae_ei cbe cbe_f tme tme_f cme cme_f tce tce_f ee ee_f ge
           pe pe_f cf cf_f cp cp_f cm cm_f cw cw_f
           cr cr_f pw pw_f pw_nl pw_nl_F te te_f te_nl te_nl_f ph ph_f ph_l ph_l_f ph_nl ph_nl_f sw sw_f ww ww_nl ww_f ww_nl_F tvs tvs_f td 
           td_f trt trt_f tabbed ET
           NAICS_NEW mr mr_f br br_f empl_a SALES_A SALES_T OPEXP_A INCOME_A WT EXP COU FIPSST SP);
 NAICS_NEW_5 = substr(NAICS_NEW,1,5);
 if ar ne 1 and NAICS_NEW_5='32732' and TABBED="Y" and TVS>0 and SP>0.90;
run;

proc sort data=concrete02; by survu_id; run;

data concf2002;
 set fhs.concf2002;
run;
proc sort data=concf2002; by survu_id; run;

/* Match active, tabulated, non-AR concrete plants in CMF to concrete plants that have a specialization ratio > 
  0.90 AND have ready-mix concrete product in the product trailer file. */

data concrete.concrete02;
 merge concrete02 (in=incmf) concf2002 (in=inprod);
by survu_id;
if incmf and inprod;
run;


data concrete07;
 set cmf.cmf2007 (KEEP=ar survu_id  firmid tab tab_f tab_ei tae tae_f tae_ei cbe cbe_f tme tme_f cme cme_f tce tce_f ee ee_f ge pe pe_f cf cf_f cp cp_f cm cm_f cw cw_f
           cr cr_f pw pw_f te te_f ph ph_f sw sw_f ww ww_f tvs tvs_f td 
           td_f trt trt_f tabbed ET
           NAICS_NEW mr mr_f br br_f empl_a SALES_A SALES_T OPEXP_A INCOME_A WT EXP COU FIPSST SP);
 NAICS_NEW_5 = substr(NAICS_NEW,1,5);
 if ar ne 1 and NAICS_NEW_5='32732' and TABBED="Y" and TVS>0 and SP>0.90 ;
run;

proc sort data=concrete07; by survu_id; run;

data concf2007;
 set fhs.concf2007;
run;
proc sort data=concf2007; by survu_id; run;

/* Match active, tabulated, non-AR concrete plants in CMF to concrete plants that have a specialization ratio > 
  0.90 AND have ready-mix concrete product in the product trailer file. */

data concrete.concrete07;
 merge concrete07 (in=incmf) concf2007 (in=inprod);
by survu_id;
if incmf and inprod;
run;



